#ifndef LookAt_h
#define LookAt_h

class CAttachment;


#define LOOKIK_BLEND_RATIOS 5
class CLookAt :
	public IAnimationPoseModifier
{
	CRYINTERFACE_BEGIN()
		CRYINTERFACE_ADD(IAnimationPoseModifier)
	CRYINTERFACE_END()

	CRYGENERATE_CLASS(CLookAt, "AnimationPoseModifier_LookAt", 0xd40464299f4f47d3, 0xa5a8aa1a7ff5d365)

public:
	void Init();

private:
	void ComputeNewSpineAndHeadOrientation(const SAnimationPoseModiferParams& params, QuatT* pRelativeQuatIK, Quat &relHeadQuat);
	void CalculateEyeLookDirection(const SAnimationPoseModiferParams& params, Vec3 &CamPos, QuatT* pRelativeQuatIK);

	bool ExecuteLocal(const SAnimationPoseModiferParams& params);

	// IAnimationPoseModifier
public:
	virtual bool Prepare(const SAnimationPoseModiferParams& params);
	virtual bool Execute(const SAnimationPoseModiferParams& params);
	virtual void Synchronize();

	void GetMemoryUsage(ICrySizer *pSizer) const
	{
		pSizer->AddObject(this, sizeof(*this));
	}

public://private:
	Quat m_oldSpine1;
	Quat m_oldSpine2;
	Quat m_oldSpine3;
	Quat m_oldNeck;
	Quat m_oldNeck1;
	Quat m_oldHead;
	Quat m_oldEyeLeft;
	Quat m_oldEyeRight;

	Vec3 m_LookDirection;		//just for debugging

	Vec3 m_LookIKTarget;
	Vec3 m_LookIKTargetSmooth;
	Vec3 m_LookIKTargetSmoothRate;

	f32 m_LookIKBlend;
	f32 m_LookIKFOR;

	f32 m_lookIKBlends[LOOKIK_BLEND_RATIOS];
	f32 m_lookIKBlendsSmooth[LOOKIK_BLEND_RATIOS];
	f32 m_lookIKBlendsSmoothRate[LOOKIK_BLEND_RATIOS];

	uint16 m_LookIKFadeout;

	uint8 m_UseLookIK;
	uint8 m_AllowAdditionalTransforms;

	Quat	m_addHead; 
	Quat	m_addLEye; 
	Quat	m_addREye; 

private:
	CAttachment* m_pAttachmentEyeLeft;
	CAttachment* m_pAttachmentEyeRight;

	QuatT m_ql;
	QuatT m_qr;

	f32 m_IKBlend;
	Quat m_additionalRotationLeft;
	Quat m_additionalRotationRight;
};

#endif // LookAt_h
